package com.jalarbee.core.util;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class ServiceCallLogger {

	private Logger logger = Logger.getLogger(ServiceCallLogger.class);

	@Pointcut("execution(* com.jalarbee.clearing.cart.service.*Service*.*(..))")
	public void serviceMethodCall() {
	}

	@Before("serviceMethodCall()")
	public void before(JoinPoint joinPoint) {
		logger.info("Before calling " + joinPoint.getSignature().getName()
				+ " with argument " + joinPoint.getArgs()[0]);
	}
	@After("serviceMethodCall()")
	public void after(JoinPoint joinPoint) {
		logger.info("After returning " + joinPoint.getSignature().getName()
				+ " with argument " + joinPoint.getArgs()[0]);
	}
}
